<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- linux.qdoc -->
  <title>Qt for Linux/X11 - Deployment | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Qt for Linux/X11 - Deployment</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#static-linking">Static Linking</a></li>
<li class="level2"><a href="#building-qt-statically">Building Qt Statically</a></li>
<li class="level2"><a href="#linking-the-application-to-the-static-version-of-qt">Linking the Application to the Static Version of Qt</a></li>
<li class="level1"><a href="#shared-libraries">Shared Libraries</a></li>
<li class="level2"><a href="#building-qt-as-a-shared-library">Building Qt as a Shared Library</a></li>
<li class="level2"><a href="#linking-the-application-to-qt-as-a-shared-library">Linking the Application to Qt as a Shared Library</a></li>
<li class="level2"><a href="#creating-the-application-package">Creating the Application Package</a></li>
<li class="level1"><a href="#application-dependencies">Application Dependencies</a></li>
<li class="level2"><a href="#additional-libraries">Additional Libraries</a></li>
<li class="level2"><a href="#qt-plugins">Qt Plugins</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt for Linux/X11 - Deployment</h1>
<span class="subtitle"></span>
<!-- $$$linux-deployment.html-description -->
<div class="descr"> <a name="details"></a>
<p>This documentation discusses specific deployment issues for <a href="linux.html">Qt for Linux/X11</a>. We will demonstrate the procedures in terms of deploying the <a href="../qtwidgets/qtwidgets-tools-plugandpaint-app-example.html">Plug &amp; Paint</a> application that is provided in Qt's examples directory.</p>
<p>Due to the proliferation of Unix systems (such as commercial Unixes, Linux distributions, and so on), deployment on Unix is a complex topic. Before we start, be aware that programs compiled for one Unix flavor will probably not run on a different Unix system. For example, unless you use a cross-compiler, you cannot compile your application on Irix and distribute it on AIX.</p>
<a name="static-linking"></a>
<h2 id="static-linking">Static Linking</h2>
<p>Static linking is often the safest and easiest way to distribute an application on Unix since it relieves you from the task of distributing the Qt libraries and ensuring that they are located in the default search path for libraries on the target system.</p>
<a name="building-qt-statically"></a>
<h3 id="building-qt-statically">Building Qt Statically</h3>
<p>To use this approach, you must start by installing a static version of the Qt library:</p>
<pre class="cpp">

  cd <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type"><a href="../qtcore/qt.html">Qt</a></span>
  <span class="operator">.</span><span class="operator">/</span>configure <span class="operator">-</span><span class="keyword">static</span> <span class="operator">-</span>prefix <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type"><a href="../qtcore/qt.html">Qt</a></span> <span class="operator">&lt;</span>other parameters<span class="operator">&gt;</span>
  make

</pre>
<p>We specify the prefix so that we do not overwrite the existing Qt installation. The example above only builds the Qt libraries, i.e&#x2e; the examples and Qt Designer will not be built. When <code>make</code> is done, you will find the Qt libraries in the <code>/path/to/Qt/lib</code> directory.</p>
<p>When linking your application against static Qt libraries, note that you might need to add more libraries to the <code>LIBS</code> line in your project file. For more information, see the <a href="windows-deployment.html#application-dependencies">Application Dependencies</a> section.</p>
<a name="linking-the-application-to-the-static-version-of-qt"></a>
<h3 id="linking-the-application-to-the-static-version-of-qt">Linking the Application to the Static Version of Qt</h3>
<p>Once Qt is built statically, the next step is to regenerate the makefile and rebuild the application. First, we must go into the directory that contains the application:</p>
<pre class="cpp">

  cd <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">/</span>examples<span class="operator">/</span>widgets<span class="operator">/</span>tools<span class="operator">/</span>plugandpaint<span class="operator">/</span>app

</pre>
<p>Now run qmake to create a new makefile for the application, and do a clean build to create the statically linked executable:</p>
<pre class="cpp">

  make clean
  PATH<span class="operator">=</span><span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">/</span>bin:$PATH
  <span class="keyword">export</span> PATH
  qmake <span class="operator">-</span>config release
  make

</pre>
<p>You probably want to link against the release libraries, and you can specify this when invoking <code>qmake</code>. Note that we must set the path to the static Qt that we just built.</p>
<p>To check that the application really links statically with Qt, run the <code>ldd</code> tool (available on most Unices):</p>
<pre class="cpp">

  ldd <span class="operator">.</span><span class="operator">/</span>application

</pre>
<p>Verify that the Qt libraries are not mentioned in the output.</p>
<p>Now, provided that everything compiled and linked without any errors, we should have a <code>plugandpaint</code> file that is ready for deployment. One easy way to check that the application really can be run stand-alone is to copy it to a machine that doesn't have Qt or any Qt applications installed, and run it on that machine.</p>
<p>Remember that if your application depends on compiler specific libraries, these must still be redistributed along with your application. For more information, see the <a href="windows-deployment.html#application-dependencies">Application Dependencies</a> section.</p>
<p>The <a href="../qtwidgets/qtwidgets-tools-plugandpaint-app-example.html">Plug &amp; Paint</a> example consists of several components: The core application (<a href="../qtwidgets/qtwidgets-tools-plugandpaint-app-example.html">Plug &amp; Paint</a>), and the <a href="../qtwidgets/qtwidgets-tools-plugandpaint-plugins-basictools-example.html">Basic Tools</a> and <a href="../qtwidgets/qtwidgets-tools-plugandpaint-plugins-extrafilters-example.html">Extra Filters</a> plugins. Since we cannot deploy plugins using the static linking approach, the executable we have prepared so far is incomplete. The application will run, but the functionality will be disabled due to the missing plugins. To deploy plugin-based applications we should use the shared library approach.</p>
<a name="shared-libraries"></a>
<h2 id="shared-libraries">Shared Libraries</h2>
<p>We have two challenges when deploying the <a href="../qtwidgets/qtwidgets-tools-plugandpaint-app-example.html">Plug &amp; Paint</a> application using the shared libraries approach: The Qt runtime has to be correctly redistributed along with the application executable, and the plugins have to be installed in the correct location on the target system so that the application can find them.</p>
<a name="building-qt-as-a-shared-library"></a>
<h3 id="building-qt-as-a-shared-library">Building Qt as a Shared Library</h3>
<p>We assume that you already have installed Qt as a shared library, which is the default when installing Qt, in the <code>/path/to/Qt</code> directory.</p>
<a name="linking-the-application-to-qt-as-a-shared-library"></a>
<h3 id="linking-the-application-to-qt-as-a-shared-library">Linking the Application to Qt as a Shared Library</h3>
<p>After ensuring that Qt is built as a shared library, we can build the <a href="../qtwidgets/qtwidgets-tools-plugandpaint-app-example.html">Plug &amp; Paint</a> application. First, we must go into the directory that contains the application:</p>
<pre class="cpp">

  cd <span class="operator">/</span>path<span class="operator">/</span>to<span class="operator">/</span><span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">/</span>examples<span class="operator">/</span>tools<span class="operator">/</span>plugandpaint

</pre>
<p>Now run qmake to create a new makefile for the application, and do a clean build to create the dynamically linked executable:</p>
<pre class="cpp">

  make clean
  qmake <span class="operator">-</span>config release
  make

</pre>
<p>This builds the core application, the following will build the plugins:</p>
<pre class="cpp">

  cd <span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>plugandpaint<span class="operator">/</span>plugins
  make clean
  qmake <span class="operator">-</span>config release
  make

</pre>
<p>If everything compiled and linked without any errors, we will get a <code>plugandpaint</code> executable and the <code>libpnp_basictools.so</code> and <code>libpnp_extrafilters.so</code> plugin files.</p>
<a name="creating-the-application-package"></a>
<h3 id="creating-the-application-package">Creating the Application Package</h3>
<p>There is no standard package management on Unix, so the method we present below is a generic solution. See the documentation for your target system for information on how to create a package.</p>
<p>To deploy the application, we must make sure that we copy the relevant Qt libraries (corresponding to the Qt modules used in the application), the <a href="windows-deployment.html#qt-plugins">platform plugin</a>, and the executable to the same directory tree. Remember that if your application depends on compiler specific libraries, these must also be redistributed along with your application. For more information, see the <a href="windows-deployment.html#application-dependencies">Application Dependencies</a> section.</p>
<p>We'll cover the plugins shortly, but the main issue with shared libraries is that you must ensure that the dynamic linker will find the Qt libraries. Unless told otherwise, the dynamic linker doesn't search the directory where your application resides. There are many ways to solve this:</p>
<ul>
<li>You can install the Qt libraries in one of the system library paths (e.g&#x2e; <code>/usr/lib</code> on most systems).</li>
<li>You can pass a predetermined path to the <code>-rpath</code> command-line option when linking the application. This will tell the dynamic linker to look in this directory when starting your application.</li>
<li>You can write a startup script for your application, where you modify the dynamic linker configuration (e.g&#x2e;, adding your application's directory to the <code>LD_LIBRARY_PATH</code> environment variable.<p><b>Note: </b>If your application will be running with &quot;Set user ID on execution,&quot; and if it will be owned by root, then LD_LIBRARY_PATH will be ignored on some platforms. In this case, use of the LD_LIBRARY_PATH approach is not an option).</p></li>
</ul>
<p>The disadvantage of the first approach is that the user must have super user privileges. The disadvantage of the second approach is that the user may not have privileges to install into the predetermined path. In either case, the users don't have the option of installing to their home directory. We recommend using the third approach since it is the most flexible. For example, a <code>plugandpaint.sh</code> script will look like this:</p>
<pre class="cpp">

  <span class="preprocessor">#!/bin/sh</span>
  appname<span class="operator">=</span>`basename $<span class="number">0</span> <span class="operator">|</span> sed s<span class="operator">,</span>\<span class="operator">.</span>sh$<span class="operator">,</span><span class="operator">,</span>`

  dirname<span class="operator">=</span>`dirname $<span class="number">0</span>`
  tmp<span class="operator">=</span><span class="string">&quot;${dirname#?}&quot;</span>

  <span class="keyword">if</span> <span class="operator">[</span> <span class="string">&quot;${dirname%$tmp}&quot;</span> <span class="operator">!</span><span class="operator">=</span> <span class="string">&quot;/&quot;</span> <span class="operator">]</span>; then
  dirname<span class="operator">=</span>$PWD<span class="operator">/</span>$dirname
  fi
  LD_LIBRARY_PATH<span class="operator">=</span>$dirname
  <span class="keyword">export</span> LD_LIBRARY_PATH
  $dirname<span class="operator">/</span>$appname <span class="string">&quot;$@&quot;</span>

</pre>
<p>By running this script instead of the executable, you are sure that the Qt libraries will be found by the dynamic linker. Note that you only have to rename the script to use it with other applications.</p>
<p>When looking for plugins, the application searches in a plugins subdirectory inside the directory of the application executable. Either you have to manually copy the plugins into the <code>plugins</code> directory, or you can set the <code>DESTDIR</code> in the plugins' project files:</p>
<pre class="cpp">

  DESTDIR = /path/to/Qt/plugandpaint/plugins

</pre>
<p>An archive distributing all the Qt libraries, and all the plugins, required to run the <a href="../qtwidgets/qtwidgets-tools-plugandpaint-app-example.html">Plug &amp; Paint</a> application, would have to include the following files:</p>
<div class="table"><table class="generic" width="100%">
 <thead><tr class="qt-style"><th >Component</th><th  colspan="2" rowspan=" 1">File Name</th></tr></thead>
<tr valign="top" class="odd"><td >The executable</td><td  colspan="2" rowspan=" 1"><code>plugandpaint</code></td></tr>
<tr valign="top" class="even"><td >The script to run the executable</td><td  colspan="2" rowspan=" 1"><code>plugandpaint.sh</code></td></tr>
<tr valign="top" class="odd"><td >The Basic Tools plugin</td><td  colspan="2" rowspan=" 1"><code>plugins\libpnp_basictools.so</code></td></tr>
<tr valign="top" class="even"><td >The ExtraFilters plugin</td><td  colspan="2" rowspan=" 1"><code>plugins\libpnp_extrafilters.so</code></td></tr>
<tr valign="top" class="odd"><td >The Qt xcb platform plugin</td><td  colspan="2" rowspan=" 1"><code>platforms\libqxcb.so</code></td></tr>
<tr valign="top" class="even"><td >The Qt Core module</td><td  colspan="2" rowspan=" 1"><code>libQt5Core.so.5</code></td></tr>
<tr valign="top" class="odd"><td >The Qt GUI module</td><td  colspan="2" rowspan=" 1"><code>libQt5Gui.so.5</code></td></tr>
<tr valign="top" class="even"><td >The Qt Widgets module</td><td  colspan="2" rowspan=" 1"><code>libQt5Widgets.so.5</code></td></tr>
</table></div>
<p>On most systems, the extension for shared libraries is <code>.so</code>. A notable exception is HP-UX, which uses <code>.sl</code>.</p>
<p>Remember that if your application depends on compiler specific libraries, these must still be redistributed along with your application. For more information, see the <a href="windows-deployment.html#application-dependencies">Application Dependencies</a> section.</p>
<p>To verify that the application now can be successfully deployed, you can extract this archive on a machine without Qt and without any compiler installed, and try to run it, i.e&#x2e; run the <code>plugandpaint.sh</code> script.</p>
<p>An alternative to putting the plugins in the <code>plugins</code> subdirectory is to add a custom search path when you start your application using <a href="../qtcore/qcoreapplication.html#addLibraryPath">QApplication::addLibraryPath</a>() or <a href="../qtcore/qcoreapplication.html#setLibraryPaths">QApplication::setLibraryPaths</a>().</p>
<pre class="cpp">

  <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>addLibraryPath(<span class="string">&quot;/some/other/path&quot;</span>);

</pre>
<a name="application-dependencies"></a>
<h2 id="application-dependencies">Application Dependencies</h2>
<a name="additional-libraries"></a>
<h3 id="additional-libraries">Additional Libraries</h3>
<p>To find out which libraries your application depends on, run the <code>ldd</code> tool (available on most Unices):</p>
<pre class="cpp">

  ldd <span class="operator">.</span><span class="operator">/</span>application

</pre>
<p>This will list all the shared library dependencies for your application. Depending on configuration, these libraries must be redistributed along with your application. In particular, the standard C++ library must be redistributed if you're compiling your application with a compiler that is binary incompatible with the system compiler. When possible, the safest solution is to link against these libraries statically.</p>
<p>You will probably want to link dynamically with the regular X11 libraries, since some implementations will try to open other shared libraries with <code>dlopen()</code>, and if this fails, the X11 library might cause your application to crash.</p>
<p>It's also worth mentioning that Qt will look for certain X11 extensions, such as Xinerama and Xrandr, and possibly pull them in, including all the libraries that they link against. If you can't guarantee the presence of a certain extension, the safest approach is to disable it when configuring Qt (e.g&#x2e; <code>./configure -no-xrandr</code>).</p>
<p>FontConfig and <a href="qt-embedded-fonts.html#freetype">FreeType</a> are other examples of libraries that aren't always available or that aren't always binary compatible. As strange as it may sound, some software vendors have had success by compiling their software on very old machines and have been very careful not to upgrade any of the software running on them.</p>
<p>When linking your application against the static Qt libraries, you must explicitly link with the dependent libraries mentioned above. Do this by adding them to the <code>LIBS</code> variable in your project file.</p>
<p>From Qt version 5.2 onwards, the officially supported version for OpenSSL is 1.0&#x2e;0 or later. Versions &gt;= 0.9&#x2e;7 and &lt; 1.0&#x2e;0 might work, but are not guaranteed to.</p>
<a name="qt-plugins"></a>
<h3 id="qt-plugins">Qt Plugins</h3>
<p>All Qt GUI applications require a plugin that implements the <a href="qpa.html">Qt Platform Abstraction</a> (QPA) layer in Qt 5. For Linux/X11, the name of the platform plugin is <code>libqxcb.so</code>. This file must be located within a specific subdirectory (by default, <code>platforms</code>) under your distribution directory. Alternatively, it is possible to adjust the search path Qt uses to find its plugins, as described below.</p>
<p>Your application may also depend on one or more Qt plugins, such as the JPEG image format plugin or a SQL driver plugin. Be sure to distribute any Qt plugins that you need with your application. Similar to the platform plugin, each type of plugin must be located within a specific subdirectory (such as <code>imageformats</code> or <code>sqldrivers</code>) within your distribution directory.</p>
<p>The search path for Qt plugins (as well as a few other paths) is hard-coded into the <a href="qtcore-module.html">QtCore</a> library. By default, the first plugin search path will be hard-coded as <code>/path/to/Qt/plugins</code>. As mentioned above, using predetermined paths has certain disadvantages, so you need to examine various alternatives to make sure that the Qt plugins are found:</p>
<ul>
<li><a href="qt-conf.html">Using <code>qt.conf</code></a>. This is the recommended approach since it provides the most flexibility.</li>
<li>Using <a href="../qtcore/qcoreapplication.html#addLibraryPath">QApplication::addLibraryPath</a>() or <a href="../qtcore/qcoreapplication.html#setLibraryPaths">QApplication::setLibraryPaths</a>().</li>
<li>Using a third party installation utility or the target system's package manager to change the hard-coded paths in the <a href="qtcore-module.html">QtCore</a> library.</li>
</ul>
<p>The <a href="plugins-howto.html">How to Create Qt Plugins</a> document outlines the issues you need to pay attention to when building and deploying plugins for Qt applications.</p>
</div>
<!-- @@@linux-deployment.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
